package com.zby.likou;

public class Demo01 {
    public static void main(String[] args) {
        int[] a = {
            1, 1, 3, 2,1
        };
        int i = new Demo01().majorityElement(a);
        System.out.println(i);
    }
    public int majorityElement(int[] nums) {
        int count = 0;
        Integer candidate = 0;

        for (int num : nums) {
            if (count == 0) {
                candidate = num;
            }
           int index =  (num == candidate) ? 1 : -1;
            count += index;
        }

        return candidate;
    }
}
